﻿using System;
using NUnit.Framework;
using Optparse;
using Optparse.Tester.Proxy;

namespace Optparse.Tester {
    [TestFixture]
    public class CommandParserTester {
        [Test]
        public void TestParseMethod() {
            CommandParserProxy proxy = new CommandParserProxy("   console.exe -f -i 127.0.0.1 -p 900 --filename  C:\\DATA\\PERSONAL\\Trunk\\a.txt --other \"C:\\Program Files\\NUnit 2.6\\bin\\a.txt\"");
            Assert.IsTrue(!proxy.EOF);

            string token = proxy.NextToken();
            Assert.AreEqual("console.exe", token);
            Assert.IsTrue(!proxy.EOF);

            token = proxy.NextToken();
            Assert.AreEqual("-f", token);
            Assert.IsTrue(!proxy.EOF);

            token = proxy.NextToken();
            Assert.AreEqual("-i", token);
            Assert.IsTrue(!proxy.EOF);

            token = proxy.NextToken();
            Assert.AreEqual("127.0.0.1", token);
            Assert.IsTrue(!proxy.EOF);

            token = proxy.NextToken();
            Assert.AreEqual("-p", token);
            Assert.IsTrue(!proxy.EOF);

            token = proxy.NextToken();
            Assert.AreEqual("900", token);
            Assert.IsTrue(!proxy.EOF);

            token = proxy.NextToken();
            Assert.AreEqual("--filename", token);
            Assert.IsTrue(!proxy.EOF);

            token = proxy.NextToken();
            Assert.AreEqual("C:\\DATA\\PERSONAL\\Trunk\\a.txt", token);
            Assert.IsTrue(!proxy.EOF);

            token = proxy.NextToken();
            Assert.AreEqual("--other", token);
            Assert.IsTrue(!proxy.EOF);

            token = proxy.NextToken();
            Assert.AreEqual("C:\\Program Files\\NUnit 2.6\\bin\\a.txt", token);
            Assert.IsTrue(proxy.EOF);
        }

        [Test]
        public void TestUnvalidParseMethod() {
            CommandParserProxy proxy = new CommandParserProxy("   console.exe -f \"C:\\DATA\\PERSONAL\\Trunk\\a.txt");
            string token = proxy.NextToken();
            Assert.AreEqual("console.exe", token);
            Assert.IsTrue(!proxy.EOF);

            token = proxy.NextToken();
            Assert.AreEqual("-f", token);
            Assert.IsTrue(!proxy.EOF);

            Assert.Throws<CommandLineParserException>(new TestDelegate(() => {
                token = proxy.NextToken();
                Assert.AreEqual("C:\\DATA\\PERSONAL\\Trunk\\a.txt", token);
            }));

            Assert.IsTrue(proxy.EOF);
        }
    }
}
